<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>YXMall欢迎登录</title>
    <style>
        body {
            font-family: PingFang SC, Helvetica Neue, Helvetica, Arial, Hiragino Sans GB, Microsoft Yahei, \5FAE软雅黑, STHeiti, \534E文细黑, sans-serif;
            color: #666;
            font-size: 12px;
            margin: 0;
            background-size: cover;
            text-align: center;
        }

        * {
            padding: 0;
            margin: 0;
        }

        .card {
            width: 450px;
            height: 567px;
            margin: 100px auto;
            border-radius: 10px;
            overflow: hidden;
            border: 1px solid #666666;
        }

        li {
            list-style-type: none;
        }

        .top {
            height: 61px;
            color: #666666;
            font-size: 20px;
            line-height: 61px;
        }

        .card_b > div > input {
            display: block;
            margin: 0 auto 15px;
            width: 370px;
            height: 50px;
            border-radius: 7px;
            padding-left: 20px;
            font-size: 15px;
            border: 1px solid #666666;
        }


        .card_b {
            padding-top: 39px;
        }

        .button {
            display: block;
            width: 372px;
            height: 50px;
            margin: 30px auto;
            border: 0;
            background-color: rgb(86, 126, 225);
            border-radius: 3px;
            color: white;
            font-size: 20px;
            position: relative;
        }

        a {
            color: blue;
            text-decoration: none;
        }

        hr {
            width: 372px;
            margin: 40px auto 20px;
        }

        .top {
            width: 450px;
            height: 200px;
            text-align: center;
        }

        .top img {
            margin-top: 49px;
        }

        .top p {
            margin-top: -20px;
        }
        #eye{
            position: absolute;
            right: 585px;
            top:420px;
        }


    </style>
</head>
<body>
<div id="app">
    <div class="card">
        <div class="top">
            <img src="imgs/logo1.png" width="120px" alt="">
            <p>使用YXMall账号登录官网</p>
        </div>

        <div class="card_b">
            <div>
                <input type="text" v-model="user.username" placeholder="用户名">

                <input id="1"  type="password" v-model="user.password" placeholder="密码">
                <img id="eye"  src="imgs/eye1.jpg" width="30px"  @click="isShow()">
            </div>

            <input type="checkbox" v-model="user.rem"> 是否记住密码

            <input class="button" type="button" @click="login()" value="登录">

            <hr>
            <span>其他账号登录： </span>
        </div>

    </div>


</div>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src=" https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script>
    let flag = true;
    let v = new Vue({
        el: "#app",
        data: function () {
            return {
                user: {
                    username: "",
                    password: "",
                    rem:false
                },

            }
        },
        methods: {
            isShow(){
                if(flag){
                    document.getElementById("1").type = "text";
                    document.getElementById("eye").src = "imgs/eye.jpg"
                    flag=false;
                }else {
                    document.getElementById("1").type = "password";
                    document.getElementById("eye").src = "imgs/eye1.jpg";
                    flag=true;
                }
            },
            login() {
                axios.post("/login", v.user).then(function (response) {
                    if (response.data == 1) {
                        location.href = '/';
                    } else if (response.data == 2) {
                        alert("用户名不存在，请重新输入")
                    } else {
                        alert("密码错误，请重新输入")
                    }
                })
            }
        },
        created:function () {
            //username=tom; password=123456
            let arr = document.cookie.split(";");
            //遍历
            for (let cookie of arr) {
                //username=tom或password=123456
                let cookieArr = cookie.split("=");
                let name = cookieArr[0].trim();
                let value = cookieArr[1];
                if (name=="username"){
                    this.user.username=value;
                }else if(name=="password"){
                    this.user.password=value;
                }
            }
        }
    })
</script>
</body>
</html>